/**
 * Copyright (c) 2021-2028, iron.guo 郭成杰 (jiedreams@sina.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.beluga.mybatis.controller;

import com.beluga.core.BelugaExcel;
import com.beluga.core.annotation.BelugaController;
import com.beluga.mybatis.entity.WxShop;
import com.beluga.mybatis.service.WxShopService;
import lombok.SneakyThrows;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author iron.guo
 * @Date 2022/5/22
 * @Description
 */
@BelugaController("demo")
public class demoController {

    @Autowired
    private WxShopService shopService;

    @GetMapping("testout")
    public void testout(HttpServletResponse httpServletResponse){
        List l= Lists.newArrayList();
        demoentity e=new demoentity();
        e.setName("aa").setPhone("12345");
        demoentity b=new demoentity();
        b.setName("aa").setPhone("12345");
        l.add(e);
        l.add(b);
        BelugaExcel.ExportBuilder(httpServletResponse,demoentity.class)
                .exportResponse(l);
    }

    @GetMapping("testoutdb")
    public String testoutdb(){
        shopService.list();
        return "111";
    }

    @GetMapping("aa")
    public String aa(){
        shopService.testmybatis();
        return "111";
    }

    @GetMapping("testmybatis")
    public String testmybatis() {
  //      shopService.testmybatis();
        List<WxShop> al=new ArrayList<>();
        WxShop dd=new WxShop();
        dd.setId(23l);
        dd.setShopName("测试mybatis3");
        al.add(dd);
        WxShop aa=new WxShop();
        aa.setId(24l);
        aa.setShopName("测试mybatis4");
        al.add(aa);
        // 开始时间
        long start = System.currentTimeMillis();
        // 执⾏时间（1s）
        shopService.saveBatch(al);
        System.out.println("saveBatch mybatis-plus内置方法 执⾏时长："+ (System.currentTimeMillis() - start) + "毫秒");

        return "success";
    }


    @SneakyThrows
    public static void main(String[] args) {

        /**
         * 逐条执行
         */
//        BelugaExcel.ImportBuilder(new FileInputStream(new File("/Users/guchenyu/Desktop/aa.xlsx")),  demoentity.class)
//                .importExcel(new ImportFunction<demoentity>() {
//
//                    @Override
//                    public void execute(int sheetIndex, int rowIndex, demoentity entity) {
//                        System.out.println(entity);
//                    }
//
//                    @Override
//                    public void error(ErrorEntity errorEntity) {
//
//                    }
//
//
//                });

        /**
         * 返回集合
         */
        List<Object> objects = BelugaExcel.ImportBuilder(new FileInputStream(new File("/Users/guchenyu/Desktop/aa.xlsx")), demoentity.class)
                .importExcel();
        System.out.println(objects);

    }



}
